#include <stdio.h>

void reverse(char s[]){
    int i;
    for (i = 0; s[i] != '\0'; ++i){
        ;
    }
    --i;
    for (int j = 0; i > j; --i, ++j){
        char temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}

void itoa(int n, char s[],int m)
{
    int i = 0;
    int sign;
    if ((sign = n) < 0)
        n = -n;
    do{
        s[i++] = n % 10 + '0';
    }while((n /= 10) > 0);
    if (sign < 0)
        s[i++] = '-';
    s[i] = '\0';
    reverse (s);
    if (i < m){
        for (int j = i; j >= 0; j--){
            s[j+m-i] = s[j];
        }
        for (int j = m - i - 1; j >= 0; --j){
            s[j] = ' ';
        }
    }
}

int main()
{
    int n;
    char s[100];
    n = 123456789;
    itoa ( n, s, 20);
    for (int i = 0; s[i] != '\0'; ++i){
        printf("%c", s[i]);
    }
    printf("\n");

    return 0;
}
